﻿// JScript File

//this function calculate age in years and months
function getAgeInYearsAndMonths(DOB, AgeInYears,AgeInMonths)
     {
         var txtDOB= document.getElementById(DOB).value;
         var txtAgeInYears= document.getElementById(AgeInYears);
         var txtAgeInMonths= document.getElementById(AgeInMonths); 
         var AgeInDays;
        
        var dt= new Date(txtDOB);
         month = dt.getMonth();
         date = dt.getDate();
         year = dt.getFullYear();
         

         if (month != parseInt(month)) { alert('Type Month of birth in digits only!'); return false; }
         if (date != parseInt(date)) { alert('Type Date of birth in digits only!'); return false; }
         if (year != parseInt(year)) { alert('Type Year of birth in digits only!'); return false; }
         if (year.length < 4) { alert('Type Year of birth in full!'); return false; }

         today = new Date();
         dateStr = today.getDate();
         monthStr = today.getMonth();
         yearStr = today.getFullYear();

         theYear = yearStr - year;
         theMonth = monthStr - month;
         theDate = dateStr - date;

         var days = "";
         if (monthStr == 0 || monthStr == 2 || monthStr == 4 || monthStr == 6 || monthStr == 7 || monthStr == 9 || monthStr == 11) days = 31;
         if (monthStr == 3 || monthStr == 5 || monthStr == 8 || monthStr == 10) days = 30;
         if (monthStr == 1) days = 28;

         txtAgeInYears.value = theYear;

         if (month < monthStr && date > dateStr) 
             { 
                    txtAgeInYears.value = parseInt(txtAgeInYears.value) + 1;
                    txtAgeInMonths.value = theMonth - 1;
             }
         if (month < monthStr && date <= dateStr)
              { 
                txtAgeInMonths.value = theMonth; 
              }
         else if (month == monthStr && (date < dateStr || date == dateStr)) 
            {
                txtAgeInMonths.value = 0; 
            }
         else if (month == monthStr && date > dateStr)
            { 
                txtAgeInMonths.value = 11;
            }
         else if (month > monthStr && date <= dateStr) 
            { 
                 txtAgeInYears.value = txtAgeInYears.value - 1;
                 txtAgeInMonths.value = ((12 - -(theMonth)) + 1);
            }
         else if (month > monthStr && date > dateStr) 
            {
                txtAgeInMonths.value = ((12 - -(theMonth)));
            }
         if (date < dateStr) 
            {
                 AgeInDays = theDate; 
            }
         else if (date == dateStr) 
             { 
                 AgeInDays = 0; 
             }
         else 
            {
                 txtAgeInYears.value = txtAgeInYears.value - 1;
                 AgeInDays = days - (-(theDate));
            }

    }
//--------------------------------------------------------------------------




function validateSalesManagerddl()
{
   
      var productKitFrom1= document.getElementById("txtProductKitFrom1").value;
      var productKitTo1= document.getElementById("txtProductKitTo1").value;
      
      var productKitFrom2= document.getElementById("txtProductKitFrom2").value;
      var productKitTo2= document.getElementById("txtProductKitTo2").value;
      
      var productKitFrom3= document.getElementById("txtProductKitFrom3").value;
      var productKitTo3= document.getElementById("txtProductKitTo3").value;
      
      var productKitFrom4= document.getElementById("txtProductKitFrom4").value;
      var productKitTo4= document.getElementById("txtProductKitTo4").value;
      
      var productKitFrom5= document.getElementById("txtProductKitFrom5").value;
      var productKitTo5= document.getElementById("txtProductKitTo5").value;
      
      
         if (productKitFrom1 != "" && productKitTo1!= "")
           {
             var ddlSM1 = document.getElementById("ddlSalesManager1");
                if(ddlSM1.value ==0 || ddlSM1.value == -1)
                {
                    alert("Please select Sales Manager");
                }
           }
           
           if (productKitFrom2 != "" && productKitTo2!= "")
           {
             var ddlSM2 = document.getElementById("ddlSalesManager2");
                if(ddlSM2.value ==0 || ddlSM2.value == -1)
                {
                    alert("Please select Sales Manager");
                }
           }
           
           if (productKitFrom3 != "" && productKitTo3!= "")
           {
             var ddlSM3 = document.getElementById("ddlSalesManager3");
                if(ddlSM3.value ==0 || ddlSM3.value == -1)
                {
                    alert("Please select Sales Manager");
                }
           }
           
           if (productKitFrom4 != "" && productKitTo4!= "")
           {
             var ddlSM4 = document.getElementById("ddlSalesManager4");
                if(ddlSM4.value ==0 || ddlSM4.value == -1)
                {
                    alert("Please select Sales Manager");
                }
           }
           
           if (productKitFrom5 != "" && productKitTo5!= "")
           {
             var ddlSM5 = document.getElementById("ddlSalesManager5");
                if(ddlSM5.value ==0 || ddlSM5.value == -1)
                {
                    alert("Please select Sales Manager");
                }
           }
}


